import http, {HttpOptions} from "../http";

// 响应接口
export interface GetHouseholdByFamilyIdRes {
    code: number;
    msg: string;
    data: {
        id: number;
        familyId: number;
        userId: number;
        householdName: string;
        householdRmake: string;
        phone: string;
        cardNum: string;
        sex: string;
        ethnicGroup: string;
        birthDate: string;
        communilyId: number;
        communilyName: string;
        curReside: string;
        updateBy: string;
        updateTime: string;
    }[];
    timestamp: number;
    now: string;
}

/**
 * 根据家庭id获取住户
 * @param {string} familyId
 * @returns
 */
export function getHouseholdByFamilyId(familyId: number): Promise<GetHouseholdByFamilyIdRes> {
    const config: HttpOptions = {
        msg: false,
        token: true,
        load: false,
    }
    return http.get(`/household/${familyId}`, config);
}

// 参数接口
export interface CreateHouseholdParams {
    id?: number;
    familyId?: number;
    userId?: number;
    householdName: string;
    householdRmake?: string;
    phone?: string;
    cardNum?: string;
    sex?: boolean;
    ethnicGroup?: string;
    birthDate?: string;
    communilyId?: number;
    curReside?: string;
    updateBy?: string;
    updateTime?: string;
}

// 响应接口
export interface CreateHouseholdRes {
    code: number;
    msg: string;
    data: Record<string, unknown>;
    timestamp: number;
    now: string;
}

/**
 * 创建住户
 * @param {object} params 住户信息
 * @param {number} params.id 住户ID
 * @param {number} params.familyId 隶属家庭ID
 * @param {number} params.userId 关联用户ID（有系统账号时填写）
 * @param {string} params.householdName 住户姓名
 * @param {string} params.householdRmake 住户备注
 * @param {string} params.phone 手机号码
 * @param {string} params.cardNum 身份证号
 * @param {boolean} params.sex 性别：true-男 false-女
 * @param {string} params.ethnicGroup 民族
 * @param {string} params.birthDate 出生日期
 * @param {number} params.communilyId 小区ID
 * @param {string} params.curReside 现居住地址
 * @param {string} params.updateBy 最后更新人
 * @param {string} params.updateTime 最后更新时间
 * @returns
 */
export function createHousehold(params: CreateHouseholdParams): Promise<CreateHouseholdRes> {
    const config: HttpOptions = {
        msg: false,
        token: true,
        load: false,
    }
    return http.post(`/household`, params,config);
}


// 响应接口
export interface GetHouseholdByIdRes {
    code: number;
    msg: string;
    data: {
        id: number;
        familyId: number;
        userId: number;
        householdName: string;
        householdRmake: string;
        phone: string;
        cardNum: string;
        sex: string;
        ethnicGroup: string;
        birthDate: string;
        communilyId: number;
        communilyName: string;
        curReside: string;
        updateBy: string;
        updateTime: string;
    };
    timestamp: number;
    now: string;
}

/**
 * 根据住户id获取住户
 * @param {string} id
 * @returns
 */
export function getHouseholdById(id: number): Promise<GetHouseholdByIdRes> {
    return http.get(`/household/household/${id}`);
}

// 响应接口
export interface GetCommunitySelectListRes {
    code: number;
    msg: string;
    data: {
        total: number;
        size: number;
        current: number;
        records: {
            key: number;
            propertyId: number;
            communityName: string;
        }[];
    };
    timestamp: number;
    now: string;
}

/**
 * 查询小区列表， select页面对象
 * @param {string} page
 * @param {string} size
 * @returns
 */
export function getCommunitySelectList(page: number, size: number): Promise<GetCommunitySelectListRes> {
    const config:HttpOptions  = {
        msg: false,
        token: true,
        load: false,
    }
    return http.get(`/community/list/select?page=${page}&size=${size}`,config);
}


// 参数接口
export interface UpdateHouseholdParams {
    id?: number;
    familyId?: number;
    userId?: number;
    householdName: string;
    householdRmake?: string;
    phone?: string;
    cardNum?: string;
    sex?: boolean;
    ethnicGroup?: string;
    birthDate?: string;
    communilyId?: number;
    curReside?: string;
    updateBy?: string;
    updateTime?: string;
}

// 响应接口
export interface UpdateHouseholdRes {
    code: number;
    msg: string;
    data: Record<string, unknown>;
    timestamp: number;
    now: string;
}

/**
 * 更新住户信息
 * @param {object} params 住户信息
 * @param {number} params.id 住户ID
 * @param {number} params.familyId 隶属家庭ID
 * @param {number} params.userId 关联用户ID（有系统账号时填写）
 * @param {string} params.householdName 住户姓名
 * @param {string} params.householdRmake 住户备注
 * @param {string} params.phone 手机号码
 * @param {string} params.cardNum 身份证号
 * @param {boolean} params.sex 性别：true-男 false-女
 * @param {string} params.ethnicGroup 民族
 * @param {string} params.birthDate 出生日期
 * @param {number} params.communilyId 小区ID
 * @param {string} params.curReside 现居住地址
 * @param {string} params.updateBy 最后更新人
 * @param {string} params.updateTime 最后更新时间
 * @returns
 */
export function updateHousehold(params: UpdateHouseholdParams): Promise<UpdateHouseholdRes> {
    const config:HttpOptions  = {
        msg: false,
        token: true,
        load: false,
    }
    return http.put(`/household`, params,config);
}


// 响应接口
export interface DeleteHouseholdRes {
    code: number;
    msg: string;
    data: Record<string, unknown>;
    timestamp: number;
    now: string;
}

/**
 * 删除住户
 * @param {string} id
 * @returns
 */
export function deleteHousehold(id: number): Promise<DeleteHouseholdRes> {
    const config:HttpOptions  = {
        msg: false,
        token: true,
        load: false,
    }
    return http.delete(`/household/${id}`, config);
}
